#include "startstop.h"

#include <QDebug>

StartStop::StartStop():Process()
{
    name = "StartStop";

}
StartStop::~StartStop()
{
}

void StartStop::Run()
{
    LogManager::getSingleton().Message("StartStop", "step "+LogManager::getSingleton().toStr(currentStep));
    switch(currentStep){
    case 0:{
        ResourceAllocator::getSingleton().addResource(new InputDevice(id));
        ResourceAllocator::getSingleton().addResource(new OutputDevice(id));
        ResourceAllocator::getSingleton().addResource(new UserMemory(id));
        for (int i = 0; i < 16; i++ ) {
            ResourceAllocator::getSingleton().addResource(new SharedMemoryBlock(id,i));
        }
    }
    break;
    case 1:{
        Planner::getSingleton().createProcess(id,READY,70,new Loader );
        Planner::getSingleton().createProcess(id,READY,70,new Reader );
        Planner::getSingleton().createProcess(id,READY,70,new Send );
        Planner::getSingleton().createProcess(id,READY,70,new Get );
        Planner::getSingleton().createProcess(id,READY,70,new MainProc );
    }
    break;
    case 2:{
        ResourceAllocator::getSingleton().askForResource("EndJob",id);
        qDebug() << "Turetu blokuotis " << state;
    }
    break;
    case 3:{
        for (intListIterator it = childProcessList.begin(); it != childProcessList.end(); ++it)
        {
        qDebug()<< (*it);
        }
        Planner::getSingleton().deleteProcess(childProcessList.back());
        childProcessList.pop_back();
        Planner::getSingleton().deleteProcess(childProcessList.back());
        childProcessList.pop_back();
        Planner::getSingleton().deleteProcess(childProcessList.back());
        childProcessList.pop_back();
        Planner::getSingleton().deleteProcess(childProcessList.back());
        childProcessList.pop_back();
        Planner::getSingleton().deleteProcess(childProcessList.back());
        childProcessList.pop_back();
        qDebug() << "Turetu visus istrint";
    }
    break;
    case 4:{

        //ResourceAllocator::getSingleton().freeResource();
    }
    break;
    default:
      qDebug() << "gg StartStope";
      exit(0);
    }
    currentStep++;
}
